package com.hosever.utils;

/**
 * html特殊字符过滤
 * @author Sever
 *
 */
public class HtmlSpecialCharFilter {
	public static String doit(String message) {  		  
        if (message == null)  
            return (null);  
  
        char content[] = new char[message.length()];  
        message.getChars(0, message.length(), content, 0);  
        StringBuilder result = new StringBuilder(content.length + 50);  
        for (int i = 0; i < content.length; i++) {  
            switch (content[i]) {  
            case '<':  
                result.append("&lt;");  
                break;  
            case '>':  
                result.append("&gt;");  
                break;  
//            case '&':  
//                result.append("&amp;");  
//                break;  
            case '"':  
                result.append("&quot;");  
                break;  
            default:  
                result.append(content[i]);  
            }  
        }  
        return (result.toString());  
	}
	
	public static String resume(String message) {  		  
        if (message == null)  
            return (null);  
  
        message = message.replace("&lt;", "<");
        message = message.replace("&gt;", ">");
//        message = message.replace("&amp;", "&");
        message = message.replace("&quot;", "\"");
        
        return (message);  
	}
}
